﻿//新增排班计划
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.BusinessPanel = function (config) {
    Ext.apply(this, config);
    var businessForm = new Ext.form.FormPanel({
        border: false,
        split: true,
        labelWidth: 80,
        labelAlign: 'right',
        collapsible: true,
        items: [{
            layout: 'column',
            border: false,
            labelSeparator: '：',
            items: [{
                columnWidth: 0.5,
                border: false,
                layout: 'form',
                items: [new Ext.form.Hidden({
                    name: 'CreatePoliceManNumber'
                })]
            }]
        }]
    });
    this.BusinessForm = businessForm;

    var businessId = this.Id;
    var editGrid = new FantastPlatform.UI.AddPersonGrid({
        height: 380,
        tbar: [{
            text: '添加',
            iconCls: 'add',
            id: 'addPersonDetail',
            tooltip: {
                text: '添加商业店铺人员',
                title: '添加商业店铺人员',
                autoHide: true
            },
            handler: function () {
                editGrid.onAddPersonClick(businessId);
            }
        }, '-', {
            text: '编辑',
            iconCls: 'edit',
            id: 'editPersonDetail',
            tooltip: {
                text: '编辑商业店铺人员',
                title: '编辑商业店铺人员',
                autoHide: true
            },
            handler: function () { editGrid.onEditPersonClick(businessId); }
        }, '-', {
            text: '移除',
            iconCls: 'delete',
            id: 'deletePersonDetail',
            handler: function () {
                var node = checkGridSelected(editGrid);
                if (node) {
                    var id = '';
                    for (var i = 0; i < node.length; i++) {
                        if (node[i].get('Id') == 0) {
                            editGrid.store.remove(node[i]);
                        } else {
                            id += node[i].get('Id') + ",";
                        }
                    }
                    id = id.substring(0, id.length - 1);
                    if (id && id != '' && id != null) {
                        Ext.Msg.confirm('提示', '确认要移除选中的数据吗？', function (btn) {
                            if (btn == 'yes') {
                                Ext.Msg.wait('正在移除数据，请稍候……', '移除数据');
                                //var fIds = getIdFromGrid(node, 'Id');
                                ajaxCalled(null, '../Service/BusinessService.aspx?Action=DeletePerson', id, editGrid, null);
                            }

                        })
                    }
                }
            }
        }, '-', {
            text: '查看/编辑车辆',
            iconCls: 'edit',
            id: 'editCarDetail',
            tooltip: {
                text: '编辑人员车辆',
                title: '编辑人员车辆',
                autoHide: true
            },
            handler: function () { editGrid.onAddCarClick(businessForm.form.getValues().CreatePoliceManNumber, 1); }
        }, '-', {
            text: '查看人员详细信息',
            iconCls: 'Check',
            id: 'CheckPersonDetail',
            tooltip: {
                text: '查看人员详细信息',
                title: '查看人员详细信息',
                autoHide: true
            },
            handler: function () { editGrid.onCheckPeopleDetailsClick(); }
        }, '-', {
            text: '查看历史住户',
            iconCls: 'checkhis',
            tooltip: {
                text: '查看历史住户',
                title: '查看历史住户',
                autoHide: true
            },
            handler: function () {
                btnCarEnable = false;
                Ext.getCmp('deletePersonDetail').setDisabled(true);
                Ext.getCmp('addPersonDetail').setDisabled(true);
                Ext.getCmp('editPersonDetail').setDisabled(true);
                editGrid.onPersonHistryCheckClick(businessId, 'Business');
            }
        }, '-', {
            text: '查看现住人员',
            iconCls: 'checknow',
            tooltip: {
                text: '查看现住人员',
                title: '查看现住人员',
                autoHide: true
            },
            handler: function () {
                btnCarEnable = true;
                Ext.getCmp('deletePersonDetail').setDisabled(false);
                Ext.getCmp('addPersonDetail').setDisabled(false);
                Ext.getCmp('editPersonDetail').setDisabled(false);
                editGrid.onPersonNowCheckClick(businessId, 'Business');
            }
        }]
    });
    editGrid.addListener('rowdblclick', function () { editGrid.onEditPersonFClick(); });

    this.BusinessPersonEditGrid = editGrid;

    this.items = [{
        columnWidth: 1,
        border: false,
        items: [businessForm]
    }, {
        columnWidth: 1,
        border: false,
        items: [editGrid]
    }];
    FantastPlatform.UI.BusinessPanel.superclass.constructor.call(this, {
        layout: 'column',
        border: false
    });
};
Ext.extend(FantastPlatform.UI.BusinessPanel, Ext.Panel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.BusinessPanel.superclass.onRender.call(this, ct, position);
        if (this.Id && this.Id != 0) {
            this.BusinessForm.add(new Ext.form.Hidden({ name: 'Id', value: this.Id }));
            var grid = this.BusinessPersonEditGrid;
            var gridId = this.Id;
            var bform = this.BusinessForm;
            this.BusinessForm.load({
                url: '../Service/BusinessService.aspx?Action=Get',
                params: { id: this.Id },
                waitMsg: '正在读取数据...',
                waitTitle: '请稍后',
                success: function (form, action) {
//                    if (form.getValues().CreatePoliceManNumber != policemanNumber) {
//                        Ext.getCmp('deletePersonDetail').setDisabled(true);
//                        Ext.getCmp('addPersonDetail').setDisabled(true);
//                        Ext.getCmp('editPersonDetail').setDisabled(true);
//                    }
                    grid.store.baseParams = { id: gridId };
                    grid.store.load({ params: { start: 0, limit: grid.paperBar.defaultNum, dir: '', sort: ''} });
                },
                failure: function (form, action) {
                    if (action.failureType != 'client') {
                        showErrorMessage('操作失败', action.result.message, '');
                    }
                }
            })

        }
    }

});  